"""
4 题目要求：
 在当前目录新建目录img, 里面包含10个文件, 10个文件名各不相同(X4G5.png)
 将当前img目录所有以.png结尾的后缀名改为.jpg.
"""
import os
import random
import string

s = string.ascii_uppercase

def create_file():
    os.mkdir('img')
    for i in range(10):
        name = random.choice(s) + str(random.randint(0, 9)) + random.choice(s) + str(random.randint(0, 10))
        with open(f'img\\{name}.png', mode='wb') as f:
            pass


def change_name():
    for i in os.listdir('img'):
        old_filepath = f'img\\{i}'
        i = os.path.splitext(i)[0]
        new_filepath = f'img\\{i}.jpg'
        os.rename(old_filepath, new_filepath)


if __name__ == '__main__':
    # create_file()
    change_name()

